package com.quiz.bis.service.impl;

import com.quiz.bis.domain.bo.BisCategorysSearchBo;
import com.quiz.bis.domain.model.BisCategories;
import com.quiz.bis.mapper.BisCategoriesMapper;
import com.quiz.bis.service.IBisCategoriesService;
import com.quiz.common.mybatis.core.query.LambdaQueryWrapperPlus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 题目分类服务层实现
 *
 * @author ahuan
 */
@Service
@RequiredArgsConstructor
public class BisCategoriesServiceImpl implements IBisCategoriesService {


    private final BisCategoriesMapper baseMapper;

    @Override
    public List<BisCategories> list(BisCategorysSearchBo categorysSearchBo) {
        LambdaQueryWrapperPlus<BisCategories> lqw = new LambdaQueryWrapperPlus<BisCategories>()
                .eqIfPresent(BisCategories::getStatus, categorysSearchBo.getStatus())
                .likeIfPresent(BisCategories::getCategoryName, categorysSearchBo.getCategoryName());
        List<BisCategories> bisCategories = baseMapper.selectList(lqw);
        return bisCategories;
    }

    @Override
    public BisCategories getById(Integer categoryId) {
        return baseMapper.selectOne(BisCategories::getCategoryId,categoryId);
    }

    @Override
    public int save(BisCategories bisCategories) {
        return baseMapper.insert(bisCategories);
    }

    @Override
    public int updateById(BisCategories bisCategories) {
        return baseMapper.updateById(bisCategories);
    }

    @Override
    public int removeById(Long categoryId) {
        return baseMapper.deleteById(categoryId);
    }
}
